<template>
	<!-- 教师 发布预习作业 考试页面 -->
	<page-body>
		<view class="page">
			<view class="flex benben-position-layout flex flex-wrap align-center fb_flex_0_ibhf"
				:style="{height:(88+StatusBarRpx)+'rpx',paddingTop:StatusBarRpx+'rpx', }">
				<view class='flex flex-wrap align-center justify-between flex-sub fb_fd0_0_ibhf'>
					<view class='flex flex-wrap align-center fb_fd0_0_c0_ibhf' @tap.stop="handleJumpDiy"
						data-type="back" data-url="1">
						<text class='fu-iconfont2  fb_fd0_0_c0_c0_ibhf'>&#xE794;</text>
					</view>
					<view class='flex flex-wrap align-stretch justify-center'>
						<text class='fb_fd0_0_c1_c0_ibhf'>{{type==1?'发布预习':type==2?'发布课后作业':'发布课程考试'}}</text>
					</view>
					<view class='flex flex-wrap align-center justify-end fb_fd0_0_c0_ibhf'>
					</view>
				</view>

			</view>
			<view :style="{height: (88+StatusBarRpx)+'rpx'}"></view>
			<!---flex布局flex布局开始-->
			<view class="flex flex-direction flex-wrap align-stretch benben-flex-layout fb_flex_1_ibhf">
				<view class='flex flex-wrap align-center justify-between fb_fd1_0_ibhf'>
					<text>{{type==1?'预习':type==3?'考试':'作业'}}名称</text>
					<benben-input class='fb_fd1_0_c1_ibhf' type="text" :placeholder="`请输入`" confirm-type="done"
						:maxlength="-1" :adjust-position='true' placeholder-style="color:#999;font-size:28rpx"
						v-model="title" />
				</view>
				<view class='flex flex-wrap align-center justify-between fb_fd1_0_ibhf' @tap.stop="opentimeFunc(1)">
					<text>{{type==1?'预习':type==3?'考试':'作业'}}开始时间</text>
					<view class='flex flex-wrap align-center'>
						<text v-if="!time1">请选择</text><text v-if="time1">{{time1}}</text>
						<text class='fu-iconfont2'>&#xe7f2;</text>
					</view>
				</view>
				<view class='flex flex-wrap align-center justify-between fb_fd1_0_ibhf' @tap.stop="opentimeFunc(2)">
					<text>{{type==1?'预习':type==3?'考试':'作业'}}结束时间</text>
					<view class='flex flex-wrap align-center'>
						<text v-if="!time2">请选择</text><text v-if="time2">{{time2}}</text>
						<text class='fu-iconfont2'>&#xe7f2;</text>
					</view>
				</view>
				<view class='flex flex-wrap align-center justify-between fb_fd1_0_ibhf' @tap.stop="jump">
					<text>发放对象</text>
					<view class='flex flex-wrap align-center'>
						<text>{{user_id?'已选择':'请选择'}}</text>
						<text class='fu-iconfont2'>&#xe7f2;</text>
					</view>
				</view>
				<view class='flex flex-wrap align-center justify-between fb_fd1_0_ibhf' v-if="type==3">
					<text>考试限时</text>
					<benben-input class='fb_fd1_0_c1_ibhf flex-sub' type="text" :placeholder="`请输入`" confirm-type="done"
						:maxlength="-1" :adjust-position='true' placeholder-style="color:#999;font-size:28rpx"
						v-model="limited_time" />
					<text>分钟</text>
				</view>

				<view class='flex flex-wrap align-center justify-between fb_fd1_0_ibhf' v-if="type==3">
					<text>允许交卷时间</text>
					<benben-input class='fb_fd1_0_c1_ibhf flex-sub' type="text" :placeholder="`请输入`" confirm-type="done"
						:maxlength="-1" :adjust-position='true' placeholder-style="color:#999;font-size:28rpx"
						v-model="xs_hand" />
					<text>分钟后</text>
				</view>
				<view class='flex flex-wrap align-center justify-between fb_fd1_0_ibhf' v-if="type==3">
					<text>及格分</text>
					<benben-input class='fb_fd1_0_c1_ibhf flex-sub' type="text" :placeholder="`请输入`" confirm-type="done"
						:maxlength="-1" :adjust-position='true' placeholder-style="color:#999;font-size:28rpx"
						v-model="pass_score" />
					<text>分</text>
				</view>
			</view>

			<!---flex布局flex布局结束-->
			<view
				class="flex flex-direction flex-wrap align-center justify-center benben-position-layout flex fb_flex_2_ibhf"
				@tap.stop='sure'>
				<button class='fb_fd2_0_ibhf'>确认发布</button>

			</view>
			<view :style="{height: '88rpx'}"></view>

			<!--选择器开始 -->
			<!-- 年月日 -->
			<!-- <benben-picker ref="benbenWritePickerCodepicker4" :visible.sync="pickerDiy1758103295108" :value.sync='time3'
				@change="checktimeFunc(chectime)" mode='date' :mask-show='true' :timeout='true' :picker-height='88'
				:current='true' fields='day' start-year='现在' end-year='2050-12-31'>
				<template #picker-header>
					<view class='flex flex-wrap align-center justify-between fb_picker4_0_ibhf'>
						<text class='fb_picker4_0_c0_ibhf' @tap="$refs.benbenWritePickerCodepicker4.cancel()">取消</text>
						<text class='fb_picker4_0_c1_ibhf'>选择时间</text>
						<text class='fb_picker4_0_c2_ibhf'
							@tap="$refs.benbenWritePickerCodepicker4.pickerConfirm()">确认</text>
					</view>
				</template>
			</benben-picker> -->
			<!-- 年月日时分秒 -->
			<benben-picker ref="benbenWritePickerCodepicker5" @change="checktimeFunc(chectime)"
				:visible.sync="pickerDiy1761290075207" :value.sync='newtime' mode='shortTerm' :mask-show='true'
				:timeout='true' :picker-height='88' :current='true' :expand='60'>
				<template #picker-header>
					<view class='flex flex-wrap align-center justify-between fb_picker4_0_ibhf'>
						<text class='fb_picker4_0_c0_ibhf' @tap="$refs.benbenWritePickerCodepicker5.cancel()">取消</text>
						<text class='fb_picker4_0_c1_ibhf'>选择时间</text>
						<text class='fb_picker4_0_c2_ibhf'
							@tap="$refs.benbenWritePickerCodepicker5.pickerConfirm()">确认</text>
					</view>
				</template>
			</benben-picker>

		</view>
	</page-body>
</template>
<script>
	export default {
		components: {},


		data() {
			return {
				"pickerDiy1758103295108": false,
				pickerDiy1761290075207: false,
				"time1": "",
				"title": "",
				/** title【名称】 **/
				"time2": "",
				"time3": 1,
				'newtime': '',
				/** time3【选择的时间】 **/
				"chectime": 1,
				/**, chectime【选择的哪个时间】 **/
				// newtime:'2025-08-31',
				homework_id: '', //作业列表ID
				user_id: '', //发放对象
				course: '', //课程id
				type: 1, //1课前预习  2课后作业 3课程考试
				answer_time: '', //考试限时
				pass_score: '', //及格标准
				limited_time:'',//限时考试时间
				xs_hand: '', //	限时提交时间

			};
		},
		computed: {

		},
		watch: {},
		onLoad(options) {
			this.homework_id = options.id
			this.course = options.course
			this.type = options.type
		},
		onUnload() {

		},
		onReady() {

		},
		onShow() {
			this.user_id = uni.getStorageSync('checkxs')
		},
		onHide() {

		},
		onResize() {

		},
		onPullDownRefresh() {

		},
		onReachBottom(e) {

		},
		onPageScroll(e) {

		},
		methods: {
			jump() {
				uni.navigateTo({
					url: '/pages/kc/teacherpeole/teacherpeole?course=' + this.course
				})
			},
			sure() {
				if (!this.title) {
					this.$message.info('请输入名称')
					return
				}
				if (!this.time1) { 
					this.$message.info('请选择开始时间')
					return
				}
				if (!this.time2) {
					this.$message.info('请选择结束时间')
					return
				}
				if (!this.user_id) {
					this.$message.info('请选择发放对象')
					return
				}
				if (this.type == 3) {
					if(!this.limited_time){
						this.$message.info('请输入考试限时时间')
						return
					}
					if (!this.xs_hand) {
						this.$message.info('请输入考试可提交限时时间')
						return
					}
					if (!this.pass_score) {
						this.$message.info('请输入及格分数')
						return
					}
				}
				console.log(this.user_id)
				let _this = this
				let cont = this.type == 1 ? '是否确认发布该预习任务?' : this.type == 2 ? '是否确认发布该作业?' : '是否确认发布该考试'
				uni.showModal({
					title: "提示",
					content: cont,
					complete(res) {
						if (res.confirm) {
							_this.tj()
						} else {
							return
						}

					}
				})
			},
			async tj() {
				let url = global.apiUrls.post68d21944cbae4
				let obj = {
					title: this.title,
					start_time: this.time1,
					end_time: this.time2,
					homework_id: this.homework_id,
					user_id: this.user_id,
				}
				if (this.type == 3) {
					url = global.apiUrls.post68f5fdeb20de2
					obj = {
						title: this.title,
						start_time: this.time1,
						end_time: this.time2,
						limited_time: this.limited_time,
						xs_hand: this.xs_hand,
						user_ids: this.user_id,
						exampaper_id: this.homework_id,
						pass_score: this.pass_score,
						// course_id:this.course_id,
						// teaching_id: this.teaching_id
					}
				}
				let datalist = await this.$api.post(url, obj);

				if (datalist.data.code != 1) {
					this.$message.info(datalist.data.msg);
					return
				}
				uni.setStorageSync('checkxs', '')
				let infolist = datalist.data;
				console.log(infolist)
				uni.navigateBack()
			},
			//选择时间
			checktimeFunc(type) {
				let newtimes = this.formatDateTimeSimple(this.newtime);
				if (type == 1) {
					this.time1 = newtimes
				} else {
					this.time2 = newtimes
				}
			},
			// 时间小于0 转换
			 formatDateTimeSimple(dateTimeStr) {
			    return dateTimeStr.replace(/\b\d{1,2}\b/g, match => 
			        match.padStart(2, '0')
			    );
			},
			//打开时间
			opentimeFunc(key) {
				this.chectime = key;
				this.pickerDiy1761290075207 = true;
			}
		}
	};
</script>
<style lang="scss" scoped>
	.page {
		width: 100vw;
		overflow-x: hidden;
		min-height: calc(100vh - var(--window-bottom));
		background: var(--benbenbgColor1);
		background-size: 100% auto;

		.fb_picker4_0_ibhf {
			padding: 0rpx 32rpx 0rpx 32rpx;
			line-height: 88rpx;
			border-bottom: 1px solid #eee;
			background-color: #ffffff;

			.fb_picker4_0_c0_ibhf {
				color: var(--benbenFontColor2);
			}

			.fb_picker4_0_c1_ibhf {
				color: var(--benbenFontColor0);
			}

			.fb_picker4_0_c2_ibhf {
				color: var(--benbenFontColor4);
			}
		}

		.fb_fd3_0_ibhf {
			padding: 0rpx 24rpx 0rpx 24rpx;
			line-height: 110rpx;
			border-radius: 24rpx 24rpx 0rpx 0rpx;
			background: rgba(248, 248, 248, 1);
			background-size: 100% auto;

			.fb_fd3_0_c0_c0_ibhf {
				margin: 0rpx 44rpx 0rpx 0rpx;
				color: rgba(20, 94, 253, 1);
				font-size: 36rpx;
			}

			.fb_fd3_0_c0_c1_ibhf {
				font-size: 36rpx;
				color: rgba(51, 51, 51, 1);
			}
		}

		.fb_fd3_1_ibhf {
			width: 750rpx;
			background: #ffffff;
			--range-bg-color: rgba(41, 121, 255, 0.13);
			--active-bg-color: rgba(41, 121, 255, 1);
		}

		.fb_fd3_2_ibhf {
			margin: 0rpx 0rpx 88rpx 0rpx;

			.fb_fd3_2_c0_ibhf {
				border-radius: 12rpx;
				width: 702rpx;
				line-height: 84rpx;
				font-size: 24rpx;
				background: #145EFD;
				color: #fff;
				height: 84rpx;
			}
		}

		.fb_flex_2_ibhf {
			width: 750rpx;
			height: 88rpx;
			overflow: hidden;
			z-index: 10;
			bottom: calc(88rpx + var(--window-bottom));

			.fb_fd2_0_ibhf {
				border-radius: 12rpx;
				width: 702rpx;
				line-height: 84rpx;
				font-size: 24rpx;
				background: #145EFD;
				color: #fff;
				height: 84rpx;
			}
		}

		.fb_flex_1_ibhf {
			margin: 0rpx 24rpx 0rpx 24rpx;
		}

		.fb_fd1_0_ibhf {
			padding: 36rpx 0rpx 36rpx 0rpx;
			border-bottom: 1px solid #eee;

			.fb_fd1_0_c1_ibhf {
				height: 50rpx;
				text-align: right;
			}
		}

		.fb_flex_0_ibhf {
			width: 750rpx;
			height: 88rpx;
			overflow: hidden;
			z-index: 10;
			top: 0rpx;
			background: #fff;
			background-size: 100% auto !important;

			.fb_fd0_0_ibhf {
				padding: 0rpx 32rpx 0rpx 32rpx;

				.fb_fd0_0_c1_c0_ibhf {
					font-size: 36rpx;
					font-weight: 700;
					color: #333333;
					line-height: 50rpx;
				}
			}
		}

		.fb_fd0_0_c0_ibhf {
			width: 120rpx;

			.fb_fd0_0_c0_c0_ibhf {
				font-size: 36rpx;
				color: #333;
			}
		}
	}
</style>
